package com.chap9;

import java.util.ArrayList;
import java.util.concurrent.CopyOnWriteArrayList;

/**
 * Created by IntelliJ IDEA.
 * User: bj910
 * Date:2023-03-25
 * Time: 4:45
 * To change this template use File | Settings | File Templates.
 */
public class ArrayListDemo3 {
    public static void main(String[] args) {
        CopyOnWriteArrayList<String> list = new CopyOnWriteArrayList<>();
        list.add("zhangsan");
        list.add("lisi");
        list.add("wangwu");
        //如果遍历期间，写一个元素，会有什么现象
        //CopyOnWriteArrayList 不会报错
        new Thread(()->list.add("xxx")).start();
        for (String str : list) {
            System.out.println(str);
        }
    }
}
